package com.atguigu.gmall.weball.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.feignclients.item.SkuDetailFeignClient;
import com.atguigu.gmall.item.vo.SkuDetailVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;


/**
 * @author lfy
 * @Description 商品详情
 * @create 2022-11-02 11:30
 */
@Controller
public class ItemController {



    @Autowired
    SkuDetailFeignClient skuDetailFeignClient;
    /**
     * 查询商品详情
     * @return
     */
    @GetMapping("/{skuId}.html")
    public String item(@PathVariable("skuId")Long skuId,
                       Model model){

        //远程调用商品详情服务返回数据
        Result<SkuDetailVo> skuDetail = skuDetailFeignClient.getSkuDetail(skuId);
        SkuDetailVo detailVo = skuDetail.getData();

        //{category1Id、category1Name、category2Id、category2Name、category3Id、category3Name}
        //1、当前商品所属的详细分类数据
        model.addAttribute("categoryView",detailVo.getCategoryView());

        //2、id、skuName、skuDefaultImg、skuImageList[]、weight
        model.addAttribute("skuInfo",detailVo.getSkuInfo());


        //3、spuSaleAttrList： 拿到当前sku所属的spu当时到底定义了多少个销售属性名和值
        model.addAttribute("spuSaleAttrList",detailVo.getSpuSaleAttrList());

        //4、valuesSkuJson： json字符串
        model.addAttribute("valuesSkuJson",detailVo.getValuesSkuJson());

        //5、商品价格
        model.addAttribute("price",detailVo.getPrice());

        return "item/index";
    }

}

